<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="scripts/jquery.min.js"></script>
<script type="text/javascript" src="scripts/basevalue.js"></script>
<script type="text/javascript" src="scripts/cookie_util.js"></script>
<script type="text/javascript">
	$(function(){
		var flg=true;
		$("#name").blur(getname);
		$("#password").blur(getPassword);
		$("#sig_in").click(function(){
			window.location.href="register.html";
		});
		$("#login").click(function(){
			var pas=$("#password").val().trim();
			var name=$("#name").val().trim();	
			if(flg){
				$.ajax({
					url:base_path+"/login.do",
					type:"post",
					data:{"name":name,"password":pas},
					dataType:"json",
					success:function(result){					
						if(result.status==0){
							var user=result.data;
							alert(result.mgs);
							addCookie("uid",user.user_id,2);
							addCookie("uname",user.user_name,2);
							window.location.href="success.do";
						}
						else{
							$("#resu_span").html(result.mgs);
						}						
					},
				   	error:function(){
				   		alert("登陆异常");
				   	}					
				});		}});
	});
	function getname(){
		$("#name_span").empty();
		flg=true;
		var name=$("#name").val().trim();					
		console.log(name);
		if(name==""){
			flg=false;
			$("#name_span").html("用户名为空");
		}
		}
		function getPassword(){
			$("#paw").html("");
			flg=true;
			var pas=$("#password").val().trim();			
			 console.log(pas);
			 if(pas==""){
				 flg=false;
				$("#paw").html("密码为空"); 
			 }
		}	
</script>
<title>登陆页面</title>
<link rel="stylesheet" href="css/log.css" /> 
</head>
<body>
	<div class="login">
	<h1>请注册登陆</h1>
	用户名:&nbsp;<input type="text" id="name" >
		<span style="color: red" id="name_span"></span><br><br>
	密&nbsp;码:&nbsp;<input type="password" id="password">
		<span style="color: red" id="paw"></span><br><br>
		<div align="center">
		<span style="color: red" id="resu_span"></span>
		<br>
		<input type="button" id ="login" value="登陆">
		<input type="button" id ="sig_in" value="注册">
		</div>
	</div>
</body>
</html>